//
//  RecordViewCell.m
//  CCBbelefitLife
//
//  Created by liurg on 16/1/2.
//  Copyright © 2016年 liurg. All rights reserved.
//

#import "RecordViewCell.h"

@implementation RecordViewCell


- ( instancetype ) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ( self = [super initWithStyle:style reuseIdentifier:reuseIdentifier] ) {
        //self.selectionStyle = UITableViewCellSelectionStyleNone;
        _startPlayBtn = [[UIButton alloc]initWithFrame:CGRectZero];
        [_startPlayBtn addTarget:self action:@selector(playRecordVoice:) forControlEvents:UIControlEventTouchUpInside];
        _shareBtn.tag = 100;
        [self.contentView addSubview:_startPlayBtn];
        _recordMusicNameLab = [[UILabel alloc]initWithFrame:CGRectZero];
        _recordMusicNameLab.font = [UIFont systemFontOfSize:14];
        _recordMusicNameLab.tag = 101;
        [self.contentView addSubview:_recordMusicNameLab];

        _shareBtn = [[UIButton alloc]initWithFrame:CGRectZero];
        _shareBtn.backgroundColor = JYColor(245, 219, 180);
        _shareBtn.layer.cornerRadius = 14;
        [_shareBtn setTitle:@"分享" forState:UIControlStateNormal];
        _shareBtn.tag = 102;
        [self.contentView addSubview:_shareBtn];
        
        _recordTimeLab = [[UILabel alloc]initWithFrame:CGRectZero];
        _recordTimeLab.textColor = [UIColor grayColor];
        _recordTimeLab.font = [UIFont systemFontOfSize:13];
        _recordTimeLab.tag = 103;
        [self.contentView addSubview:_recordTimeLab];

        _startTimeLab= [[UILabel alloc]initWithFrame:CGRectZero];
        _startTimeLab.textColor = [UIColor grayColor];
        _startTimeLab.font = [UIFont systemFontOfSize:13];
        _startTimeLab.tag = 104;
        [self.contentView addSubview:_startTimeLab];

        _endTimeLab = [[UILabel alloc]initWithFrame:CGRectZero];
        _endTimeLab.textColor = [UIColor grayColor];
        _endTimeLab.font = [UIFont systemFontOfSize:13];
        _endTimeLab.tag = 105;
        [self.contentView addSubview:_endTimeLab];
        
        _progressSlider = [[UISlider alloc] initWithFrame:CGRectZero];
       // [_progressSlider setThumbImage:[UIImage imageNamed:@"sliderThumb_small.png"] forState:UIControlStateNormal];
        _progressSlider.thumbTintColor=JYColor(233, 131, 46);
        _progressSlider.tag = 106;
        //设置已经滑过一端滑动条背景图片，会覆盖之前之前的颜色，以下相同
        _progressSlider.minimumTrackTintColor=JYColor(105, 215, 16);
        //设置未滑过一端滑动条颜色
        _progressSlider.maximumTrackTintColor=JYColor(246, 246, 246);
        [_progressSlider addTarget:self action:@selector(playChange:)
                  forControlEvents:UIControlEventValueChanged];
        _progressSlider.minimumValue = 0.0f;
        _progressSlider.maximumValue = 10.0f;
        _progressSlider.value = 0.0f;
        [self.contentView addSubview:_progressSlider];

    }
    return self;
}

-(void)updateCellWithNewData:(NSDictionary *)dataDic{
    
    //@{@"recordName":@"小酒窝",@"recordTime":@"2015/08/31 18:15",@"startTime":@"00:00",@"endTime":@"02:30"}
    
    _startPlayBtn.frame = CGRectMake(15, 35, 30 , 30);
    [_startPlayBtn setBackgroundImage:[UIImage imageNamed:@"music_play@2x.png"] forState:UIControlStateNormal];
    _shareBtn.frame = CGRectMake(mainScreenWidth-80, 15, 60, 28);
    
    _recordMusicNameLab.frame = CGRectMake(_startPlayBtn.righX+10, 10, mainScreenWidth-80-_startPlayBtn.righX, 20);//10+20+5+20+15+20
    _recordMusicNameLab.text = dataDic[@"recordName"];
    _recordTimeLab.frame = CGRectMake(_recordMusicNameLab.x,_recordMusicNameLab.bottomY + 5, _recordMusicNameLab.width, 20);
    _recordTimeLab.text = dataDic[@"recordTime"];
    _startTimeLab.frame = CGRectMake(_recordMusicNameLab.x,_recordTimeLab.bottomY + 8, 50, 20);
    _startTimeLab.text = dataDic[@"startTime"];
    _progressSlider.frame = CGRectMake(_startTimeLab.righX+5, _recordTimeLab.bottomY+10, _recordMusicNameLab.width-50, 20);

    _endTimeLab.frame = CGRectMake(_progressSlider.righX+10, _recordTimeLab.bottomY + 8, 50, 20);
    _endTimeLab.text = dataDic[@"endTime"];
    
}

-(void)playRecordVoice:(UIButton *)playBtn{
    if (self.delegate && [self.delegate respondsToSelector:@selector(playRecordVoice:)]) {
        [self.delegate playRecordVoice:playBtn];
    }
}

-(void)playChange:(UISlider *)progressSlider{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(playProgressChange:)]) {
        [self.delegate playProgressChange:progressSlider];
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
